package untils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by guo on 2017/9/13.
 */
public class JDBCUtils {
//    public static void main(String[] args) throws ClassNotFoundException, SQLException {
//        Class.forName("com.mysql.jdbc.Driver");
//        Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc","root","root");
//        if(con!=null)
//        {
//            System.out.println("ok");
//        }
//        else
//        {
//            System.out.println("error");
//        }
   // }
 private static Connection con=null;
    public static Connection getConetion()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
                con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc","root","root");
                return con;
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public void close()
    {
        try {
           con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
